# -*- encoding=utf8 -*-
__author__ = "Bryan.Chen"

from airtest.core.api import *

auto_setup(__file__)

def runTestWithRestart(cfg):
    # open tcs app
    stop_app("com.highlight.mjpe")
    start_app("com.highlight.mjpe")
    sleep(3.0) # 等待打开应用
    
    runTest(cfg)

def runTest(cfg):
    if not cfg:
        return

    for i in range(0, len(cfg)):
        moduleName = cfg[i]["moduleName"]
        print("using module %s" % moduleName)

        path = ""
        if "path" in cfg[i]:
            path = cfg[i]["path"]

        using("../Cases/%s%s.air" % (path, moduleName))
        imp_module = __import__(moduleName)

       	isRunning = False
        while True:
        	if not isRunning:
        		isRunning = True
	        	result = imp_module.runTest(cfg[i]["args"])

	        	if result == True:
	        		break
	        	elif result == False:
	        		return

        sleep(1.0)

class BaseTestCase:

    def __init__(self):
        print("%s __init__" % (__file__))
    
    def clickButton(self, btn):
        btn.click([0.5, 0.5])
    
    def runTest(self):
            
        return True

